<html>

	<head>
		<meta charset="UTF-8">
		<title>新增计量回路</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style>
			.layui-form {
				width: 35%;
			}
			
			.layui-input {
				width: 100% !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">

				<!--标题栏-->
				<p class="content_title">站点管理 &nbsp;&nbsp;>&nbsp;&nbsp;计量回路列表&nbsp;&nbsp;>&nbsp;&nbsp;编辑计量回路</p>
				<!--标题栏-->
				<form class="layui-form mt20">
					<!--<div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="text" name="status" lay-verify="required" autocomplete="off" placeholder="" class="layui-input w30">
                </div>
            </div>-->
					<div class="layui-form-item">
						<label class="layui-form-label">供工业用户</label>
						<div class="layui-input-block">
							<input type="checkbox" name="toIndustryUser" title="供工业用户">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">序号</label>
						<div class="layui-input-block">
							<input type="text" name="circuitIndex" lay-verify="required|number" autocomplete="off" placeholder="请输入序号" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">名称</label>
						<div class="layui-input-block">
							<input type="text" name="circuitName" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">简称</label>
						<div class="layui-input-block">
							<input type="text" name="circuitTitle" lay-verify="" placeholder="请输入简称" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">供应站名</label>
						<div class="layui-input-block">
							<select name="siteId" lay-verify="required" lay-search="" id="startSite">
								<option value="">请选择站名</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">输出站名</label>
						<div class="layui-input-block">
							<select name="endSiteId" lay-verify="required" lay-search="" id="endSite">
								<option value="">请选择站名</option>
								<!--<option value="1">调压站</option>-->
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">数据延时</label>
						<div class="layui-input-block">
							<input type="text" name="dataDelayed" lay-verify="required|number" placeholder="请输入数据延时时间/分钟" autocomplete="off" class="layui-input w30">
						</div>
					</div>

					<div class="layui-form-item">
						<label class="layui-form-label">自动读取评率</label>
						<div class="layui-input-block">
							<input type="text" name="autoReadFrequency" lay-verify="required|number" placeholder="自动读取评率/分钟" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">类型</label>
						<div class="layui-input-block">
							<select name="sourceType" lay-verify="required" lay-search="">
								<option value="0">供应量</option>
								<option value="1">输出量</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">单位热值</label>
						<div class="layui-input-block">
							<select name="unitHeatVal" lay-verify="required" lay-search="">
								<option value="0">请选择单位热值</option>
								<option value="1">标方</option>
								<option value="2">吉焦</option>
								<option value="3">吨</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">计量设备</label>
						<div class="layui-input-block">
							<select name="deviceCode" lay-verify="required" lay-search="" id="deviceCode">
								<option value="">请选择计量设备</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">描述</label>
						<div class="layui-input-block">
							<input type="text" name="circuitDesc" lay-verify="" placeholder="请输入描述" autocomplete="off" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			layui.use(['form', 'layedit'], function() {
				var href = window.location.href;
				var id = href.split("?")[1].split("&")[2] ? href.split("?")[1].split("&")[2].split("=")[1] : '';
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit;
				// 	请求站点数据
				ajaxGet({
					url: 'site/getListNoPage',
					async:true,
					successFull: function(res) {
						console.log(res);
						if(res.list.length != 0) {
							$.each(res.list, function(i, item) {
								$("#startSite").append('<option value="' + item.id + '">' + item.siteName + '</option>');
								$("#endSite").append('<option value="' + item.id + '">' + item.siteName + '</option>')
							})
						};
						layui.form.render('select'); //重新渲染select
					},
					errCallBack: function(res) {

					}
				});
				//	请求计量设备列表
				ajaxGet({
					url: 'ledger/getListAll',
					successFull: function(res) {
						console.log(res);
						if(res.list.length != 0) {
							$.each(res.list, function(i, item) {
								$("#deviceCode").append('<option value="' + item.deviceCode + '">' + item.deviceName + '</option>');
							})
						};
						layui.form.render('select'); //重新渲染select
					},
					errCallBack: function(res) {

					}
				})
				if(id) {
					$.ajax({
						url: baseUrl + "meteringcircuit/getById?id=" + id,
						type: "GET",
						dataType: "json",
						success: function(data) {
							console.log(data);
							if(data.toIndustryUser == 1) {
								$("[name = toIndustryUser]").siblings(".layui-unselect").addClass('layui-form-checked');
								$("[name = toIndustryUser]").val("on");
							};
							$("[name = siteId]").val(data.siteId);
							$("[name = endSiteId]").val(data.endSiteId);
							$("[name = circuitName]").val(data.circuitName);
							$("[name = circuitStatus]").val(data.circuitStatus);
							$("[name = circuitTitle]").val(data.circuitTitle);
							$("[name = circuitIndex]").val(data.circuitIndex);
							$("[name = circuitDesc]").val(data.circuitDesc);
							$("[name = autoReadFrequency]").val(data.autoReadFrequency);
							$("[name = unitHeatVal]").val(data.unitHeatVal);
							$("[name = dataDelayed]").val(data.dataDelayed);
//							$("#deviceCode").val(data.deviceCode);
							$("[name = deviceCode]").val(data.deviceCode);
							
							layui.form.render('select'); //重新渲染select
						}
					});
				}
				//监听提交
				form.on('submit(submitFilter)', function(data) {
					console.log(data.field);
					if(data.field.toIndustryUser == 'on') {
						data.field.toIndustryUser = 1
					} else {
						data.field.toIndustryUser = 0
					};
					if(data.field.siteId == data.field.endSiteId) {
						layer.msg('供应站点和输出站点不能一直', {
							icon: 6
						});
						return false;
					}
					ajaxPost({
						url: 'meteringcircuit/update',
						data: {
							id:id,
							siteId: data.field.siteId,
							endSiteId: data.field.endSiteId,
							circuitName: data.field.circuitName,
							circuitStatus: data.field.circuitStatus, //回路状态
							circuitTitle: data.field.circuitTitle,
							dataDelayed: data.field.dataDelayed,
							circuitIndex: data.field.circuitIndex,
							circuitDesc: data.field.circuitDesc,
							toIndustryUser: data.field.toIndustryUser,
							deviceCode: data.field.deviceCode,
							autoReadFrequency: data.field.autoReadFrequency,
							unitHeatVal: data.field.unitHeatVal
						},
						successFull: function(res) {
							console.log(res)
							layer.msg('修改成功', {
								icon: 6
							});
							window.location.href = "./zhandianBack.html?pos=1&childPos=1";
						},
						errCallBack: function(res) {
							layer.msg(res.msg, {
								icon: 5
							});
						}
					})
				});
			});
		</script>
	</body>

</html>